package com.personal.info;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class PersonalInfoActivity extends Activity implements OnClickListener, OnItemSelectedListener {
    /** Called when the activity is first created. */
	
	Spinner course;
	EditText nameedit, addressedit, result;
	Button enter;
	TimePicker bday;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //Setup text
        TextView nametext = (TextView) findViewById(R.id.textname);
        nametext.setText("Name");
        TextView addresstext = (TextView) findViewById(R.id.textaddress);
        addresstext.setText("Address");
        TextView bdaytext = (TextView) findViewById(R.id.textbday);
        bdaytext.setText("Birth Date");
        //Setup text boxes
        nameedit = (EditText) findViewById(R.id.editTextname);
        nameedit.setText("");
        addressedit = (EditText) findViewById(R.id.editTextaddress);
        addressedit.setText("");
        result = (EditText) findViewById(R.id.editTextresult);
        //Setup interactive things
        enter = (Button) findViewById(R.id.buttonenter);
        enter.setText("Enter");
        enter.setOnClickListener(this);
        
        course = (Spinner) findViewById(R.id.spinnercourse);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.array1,android.R.layout.simple_spinner_item);
        course.setAdapter(adapter);
        course.setOnItemSelectedListener(this);
        
        bday = (TimePicker) findViewById(R.id.timePicker);
    }
	public void onClick(View v) {
		if(v.equals(enter))
		{
			if(nameedit.getText().toString().equals("") || addressedit.getText().toString().equals("") || course.getSelectedItem().toString().equals("Course"))
			{
				Toast.makeText(this, "Please complete all fields.", Toast.LENGTH_SHORT).show();
			}
			else
			{
				result.setText(nameedit.getText().toString() + "\n" + addressedit.getText().toString() + "\n" + bday.getCurrentHour() + ":" + bday.getCurrentMinute() + "\n" + course.getSelectedItem().toString());
				nameedit.setText("");
				addressedit.setText("");
				course.setSelection(0);
			}
		}
	}
	public void onItemSelected(AdapterView<?> arg0, View v, int arg2,
			long arg3) {
		//Toast.makeText(this, course.getSelectedItem().toString(), Toast.LENGTH_LONG).show();
	}
	public void onNothingSelected(AdapterView<?> arg0) {
		//this is mostly useless, but must be present
	}
}